GBML manual / Grids

grid_height

How many rows target has - the second number grid_create(width, height, fill) was given, so the y in target[# x, y] runs from 0 up to one less than this. It is worked out when the game is built, so it costs nothing while the game runs.

Syntax

grid_height(target) -> int

Arguments

NameType
targetgrid

Returns

int

Description

Tells you how many rows target, a grid, has: the second number grid_create was given. In target[# x, y], y counts down, so it runs from 0 up to one less than grid_height(target).

A grid made with grid_create(8, 6, 0) is 6 rows tall, so grid_height gives 6. Its other size, how many columns it has, is grid_width.

Going over every cell

Put grid_height and grid_width together and you can visit the whole grid, one row at a time:

var board = grid_create(8, 6, 0);
var down = grid_height(board);                 // 6
for (var y = 0; y < grid_height(board); y++) {
    for (var x = 0; x < grid_width(board); x++) {
        board[# x, y] = x + y;                 // every cell holds how far it is from the corner
    }
}

The two loops make 6 rows of 8 cells, which is all 48 cells of the grid, each one once. Change the grid to grid_create(10, 7, 0) and the same loops cover the new grid, because they ask the grid and do not remember its size.

It costs nothing while the game runs

grid_height is not worked out while the game runs. The number is written into the game when it is built, from the size the grid was declared with: grid_create(8, 6, 0), a /// @capacity 8x6 tag, or grid<int, 8, 6>.

A grid declared with no shape, a grid declared with only a total like /// @capacity 12, and a script's parameter have no height to give. grid_height on one is refused when the project is checked - grid_width explains why, and what to do instead.

grid_height takes a grid and nothing else. Giving it an array or a list is refused.

On the GBA

A plain number written into the C++ at build time: the height the grid was declared with (`grid_create(8, 6, 0)`, `/// @capacity 8x6` or `grid<int, 8, 6>`). No call and no memory - see grid_width for why the size is read from the declaration and not from the grid, and why a grid parameter of a script has none to give.

See also: grid_widthgrid_creategrid_fill_regiongrid_copyGridsarray_lengthData containersgrid_sortgrid_shuffle_rowsgrid_shuffle_columns